<template>

	<div class="scanCode">
		<image class="logo" src="/static/logo.png"></image>
		<h3 class="title">扫码登录 案例</h3>
		<p>Nodejs + Mysql + Vue + Uni-app</p>
		<button v-if="userInfo" class="scan" type="primary" @click="scanCode">扫码登录</button>
		<button v-else @click="handleToMyPage">请先登录</button>
	</div>
		
</template>

<script>
import { mapState } from 'vuex';
	export default {
		data() {
			return {
				uuid: null,
				StorageSync: null,
				timer: null,
				loginShow:false
			}
		},
		computed:{
			...mapState(['userInfo'])
		},
		methods: {
			scanCode() {
				uni.scanCode({
				    success: (res) => {
						console.log(res);
						// 保存扫码获得的uuid
						this.uuid = res.result;
						uni.request({
							url: `http://192.168.204.211:3000/SweepStatus`,
							method: 'POST',
							data: {
								uuid: this.uuid
							},
							success: (res) => {
								console.log("ddddddd ------: ", res)
								uni.navigateTo({
									url: `/pages/login/login?uuid=${this.uuid}`
								});
							}
						});
				    }
				});
			},
			handleToMyPage(){
				uni.switchTab({
					url:'/pages/my/my'
				})
			}
		}
	}
</script>

<style>

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
	.scanCode {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20% 0;
	}
	p {
		color: #8d8d8d;
		margin-top: 10px;
	}
	.scan {
		margin-top: 30px;
	}
</style>
